<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <textarea id="area" cols="50" rows="20">
computed:{
    ...mapState(['count','mm'])
}
    </textarea>
    <button id="btn">左向右</button>
    <button id="btn1">右向左</button>
    <textarea id="result" cols="50" rows="20"></textarea>
    <script>
        document.querySelector('#btn').onclick = function(){
            var txt = document.querySelector('#area').value 
            var reg = /\[(.*)\]/g
            var arr = eval('['+reg.exec(txt)[1]+']')
            var str = `computed:{`
            arr.forEach(item=>{
                str+= `
    ${item}(){
        return this.$store.state.${item}
},` 
            })
            str += `}`
            document.querySelector('#result').value = str 
        }

        document.querySelector('#btn1').onclick = function(){
            var txt = document.querySelector('#result').value.replace(/\s/g,'')
            var arr = []
            var reg = /state\.(.*?)}/g
            var res;
            while(res = reg.exec(txt)){
                arr.push(res[1])
            }
            document.querySelector('#area').value = `
computed:{
    ...mapState(${JSON.stringify(arr)})
}
            `
        }
    </script>
</body>
</html>